import 'package:mfkb/config/Config.dart';
import 'package:mfkb/util/HttpUtil.dart';

class DynamicService {

  Future<dynamic> getDynamics(int id) async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/dynamics?id="+id.toString()) ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> up(int did , int flag) async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/up?did="+did.toString()+"&flag="+flag.toString()) ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> publish(String content , List<String> url) async{
    dynamic data ;
    try {
      String urls = "" ;
      for(var i = 0 ; i < url.length ; i++){
        urls += "&url=" + url[i] ;
      }
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/publish?content="+content.toString()+urls) ;
    } catch (e) {
      print(e) ;
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> getReplys(int id) async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/replys?id="+id.toString()) ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> dynamicDetail(int id) async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/dynamicById?id="+id.toString()) ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> reply(int id , int did , int mid , String content) async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/publishReply?did="+did.toString()+"&mid="+mid.toString()+"&content="+content+"&id="+id.toString()) ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> myReply() async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/myReply") ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> myUps() async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/myUps") ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> myDynamic() async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/myDynamic") ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> delDynamic(String id) async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/delDynamic?id="+id) ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }
}